<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
  	
  private $_id;
    public function authenticate()
    {
        $record=User::model()->findByAttributes(array('username'=>$this->username));			//используем модель User с полем username и password
        if($record===null)
            $this->errorCode=self::ERROR_USERNAME_INVALID;         							
        else if ($record->password !== crypt($this->password, $record->password))               //проверяем пароль по хешу функции crypt
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        else if($record->ban == 1)
            $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;                                    //Если забанен, то блокируем
        else
        {
            $this->_id=$record->userid;
            $this->setState('username', $record->username);
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
 
    public function getId()
    {
        return $this->_id;
    }


}